package aps.module_Core;

//forge
import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Material;
import net.minecraft.src.ModLoader;
import net.minecraftforge.common.Configuration;
import aps.BuildcraftAPS;
import aps.module;
import aps.module_Converter.ItemBottledEnergy;
import aps.module_Converter.ItemInsulatedBottle;
import aps.module_Machines.ItemEnergyCrystal;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.recipes.AssemblyRecipe;
import buildcraft.core.DefaultProps;
import buildcraft.core.utils.Localization;
import cpw.mods.fml.common.network.NetworkRegistry;
//FML
//aps
//buildcraft
//vanilla minecraft

public class module_Core extends module
{
	int ItemIdPowerCore;
	int ItemIdKit;
	int ItemIdControlPanel;
	
	int BlockIdMetaBlock;
	
	public static Item APSPowerCoreItem = null;
	public static Item APSKitItem = null;
	public static Item APSMetaBlockEnergyItem = null;
	public static Item APSMetaBlockMachineItem = null;
	public static Item APSControlPanelItem = null;
	
	public static Item insulatedBottle = null;
	public static int insulatedBottleID;
	public static Item bottledEnergy = null;
	public static int bottledEnergyID;
	
	int energyCrystalID;
	public static Item EnergyCrystal = null;
	
	public static Block APSMetaBlockEnergy = null;
	public static Block APSMetaBlockMachine = null;
	public static APSMetaSub[] APSMetaSubs = new APSMetaSub[32];
	
	public static enum APSBlockTypes { Energy, Machine };
	
	public module_Core() {}
	
	@Override
	public void preInit()
	{
		ItemIdPowerCore = Integer.parseInt(BuildcraftAPS.Conf.get(Configuration.CATEGORY_ITEM, "PowerCore.ID", BuildcraftAPS.defItemStartID + 0).value);
		ItemIdKit = Integer.parseInt(BuildcraftAPS.Conf.get(Configuration.CATEGORY_ITEM, "KitItem.ID", BuildcraftAPS.defItemStartID + 1).value);
		//ItemIdControlPanel = Integer.parseInt(BuildcraftAPS.Conf.get(Configuration.CATEGORY_ITEM, "Control Panel Item ID", BuildcraftAPS.defItemStartID + 11).value);
		
		insulatedBottleID = Integer.parseInt(BuildcraftAPS.Conf.get(Configuration.CATEGORY_ITEM, "InsulatedBottle.ID", BuildcraftAPS.defItemStartID + 2 + 11).value);
		bottledEnergyID = Integer.parseInt(BuildcraftAPS.Conf.get(Configuration.CATEGORY_ITEM, "BottledEnergy.ID", BuildcraftAPS.defItemStartID + 2 + 12).value);
		
		energyCrystalID = Integer.parseInt(BuildcraftAPS.Conf.get(Configuration.CATEGORY_ITEM, "EnergyCrystal.ID", BuildcraftAPS.defItemStartID + 2 + 15).value);
		
		BlockIdMetaBlock = Integer.parseInt(BuildcraftAPS.Conf.get(Configuration.CATEGORY_BLOCK, "MetablockStart.ID", BuildcraftAPS.defBlockStartID).value);
		
	}
	
	@Override
	public void initialize()
	{
		//Initialize GUIs for all modules (too lazy to convert all modules to individual loadable modules through FML)
		NetworkRegistry.instance().registerGuiHandler(BuildcraftAPS.instance, new GuiHandler());
		
		APSPowerCoreItem = (new ItemAPSPowerCore(ItemIdPowerCore)).setItemName("apspowercoreitem");
		APSKitItem = (new ItemAPSKit(ItemIdKit)).setItemName("apskititem");
		//APSControlPanelItem = (new ItemAPSControlPanel(ItemIdControlPanel)).setItemName("apscontrolpanelitem");
		
		APSMetaBlockEnergy = (new BlockAPSMetaEnergy(BlockIdMetaBlock, Material.iron)).setBlockName("apsmetablockenergy");
		APSMetaBlockMachine = (new BlockAPSMetaMachine(BlockIdMetaBlock + 1, Material.iron)).setBlockName("apsmetablockmachine");
		APSMetaBlockEnergyItem = (new ItemBlockAPSMeta(APSMetaBlockEnergy.blockID-256)).setItemName("apsmetablockenergyitem");
		APSMetaBlockMachineItem = (new ItemBlockAPSMeta(APSMetaBlockMachine.blockID-256)).setItemName("apsmetablockmachineitem");
		
		//####################Redstone Chipset Alternative Recipe
		ModLoader.addRecipe(new ItemStack(BuildCraftSilicon.redstoneChipset, 1, 0), new Object[]{ "rrr", " r ", "rrr",
													            Character.valueOf('r'), Item.redstone
													            });
		
		//####################Redstone Chipset Alternative Recipe
		ModLoader.addRecipe(new ItemStack(BuildCraftSilicon.redstoneChipset, 1, 1), new Object[]{ "rrr", "IrI", "rrr",
													            Character.valueOf('r'), Item.redstone,
													            Character.valueOf('I'), Item.ingotIron
													            });
				
		//####################Redstone Chipset Alternative Recipe
		/*ModLoader.addRecipe(new ItemStack(BuildCraftSilicon.redstoneChipset, 1, 2), new Object[]{ "rrr", "GrG", "rrr",
													            Character.valueOf('r'), Item.redstone,
													            Character.valueOf('G'), Item.ingotGold
													            });
		*/
		//####################Redstone Chipset Alternative Recipe
		/*ModLoader.addRecipe(new ItemStack(BuildCraftSilicon.redstoneChipset, 1, 3), new Object[]{ "rrr", "DrD", "rrr",
													            Character.valueOf('r'), Item.redstone,
													            Character.valueOf('D'), Item.diamond
													            });
		*/
		//####################Assembly Table Repair Recipes
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.pickaxeWood), new ItemStack(Block.planks, 2)}, 500, new ItemStack(Item.pickaxeWood)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.axeWood), new ItemStack(Block.planks, 2)}, 500, new ItemStack(Item.axeWood)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.shovelWood), new ItemStack(Block.planks, 1)}, 500, new ItemStack(Item.shovelWood)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.swordWood), new ItemStack(Block.planks, 1)}, 500, new ItemStack(Item.swordWood)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.hoeWood), new ItemStack(Block.planks, 1)}, 500, new ItemStack(Item.hoeWood)));
		
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.pickaxeStone), new ItemStack(Block.cobblestone, 2)}, 1000, new ItemStack(Item.pickaxeStone)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.axeStone), new ItemStack(Block.cobblestone, 2)}, 1000, new ItemStack(Item.axeStone)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.shovelStone), new ItemStack(Block.cobblestone, 1)}, 1000, new ItemStack(Item.shovelStone)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.swordStone), new ItemStack(Block.cobblestone, 1)}, 1000, new ItemStack(Item.swordStone)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.hoeStone), new ItemStack(Block.cobblestone, 1)}, 1000, new ItemStack(Item.hoeStone)));
		
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.pickaxeSteel), new ItemStack(Item.ingotIron, 2)}, 2500, new ItemStack(Item.pickaxeSteel)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.axeSteel), new ItemStack(Item.ingotIron, 2)}, 2500, new ItemStack(Item.axeSteel)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.shovelSteel), new ItemStack(Item.ingotIron, 1)}, 2500, new ItemStack(Item.shovelSteel)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.swordSteel), new ItemStack(Item.ingotIron, 1)}, 2500, new ItemStack(Item.swordSteel)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.hoeSteel), new ItemStack(Item.ingotIron, 1)}, 2500, new ItemStack(Item.hoeSteel)));
		
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.pickaxeGold), new ItemStack(Item.ingotGold, 2)}, 5000, new ItemStack(Item.pickaxeGold)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.axeGold), new ItemStack(Item.ingotGold, 2)}, 5000, new ItemStack(Item.axeGold)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.shovelGold), new ItemStack(Item.ingotGold, 1)}, 5000, new ItemStack(Item.shovelGold)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.swordGold), new ItemStack(Item.ingotGold, 1)}, 5000, new ItemStack(Item.swordGold)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.hoeGold), new ItemStack(Item.ingotGold, 1)}, 5000, new ItemStack(Item.hoeGold)));
		
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.pickaxeDiamond), new ItemStack(Item.diamond, 2)}, 10000, new ItemStack(Item.pickaxeDiamond)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.axeDiamond), new ItemStack(Item.diamond, 2)}, 10000, new ItemStack(Item.axeDiamond)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.shovelDiamond), new ItemStack(Item.diamond, 1)}, 10000, new ItemStack(Item.shovelDiamond)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.swordDiamond), new ItemStack(Item.diamond, 1)}, 10000, new ItemStack(Item.swordDiamond)));
		AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {new ItemStack(Item.hoeDiamond), new ItemStack(Item.diamond, 1)}, 10000, new ItemStack(Item.hoeDiamond)));
		
		//####################Redstone Power Core
    	ModLoader.addName(new ItemStack(APSPowerCoreItem, 1, 0), "Redstone Power Core");
    	ModLoader.addRecipe(new ItemStack(APSPowerCoreItem, 1, 0), new Object[]{ "IrI", "GRG", "IrI",
    	                                                        Character.valueOf('I'), Item.ingotIron,
    	                                                        Character.valueOf('G'), BuildCraftCore.woodenGearItem,
    	                                                        Character.valueOf('r'), Item.redstone,
    	                                                        Character.valueOf('R'), new ItemStack(BuildCraftSilicon.redstoneChipset, 1, 0)
    	                                                        });
    	                                                                
    	 //####################Iron Power Core
    	ModLoader.addName(new ItemStack(APSPowerCoreItem, 1, 1), "Iron Power Core");
    	AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {
                                                                new ItemStack(APSPowerCoreItem, 1, 0), 
                                                                new ItemStack(Item.ingotIron, 2)}, 
                                                                5000, 
                                                                new ItemStack(APSPowerCoreItem, 1, 1)
                                                                ));
    	/*ModLoader.addRecipe(new ItemStack(APSPowerCoreItem, 1, 1), new Object[]{ "IrI", "GRG", "IrI",
                                                                Character.valueOf('I'), Item.ingotIron,
                                                                Character.valueOf('G'), BuildCraftCore.ironGearItem,
                                                                Character.valueOf('r'), Item.redstone,
                                                                Character.valueOf('R'), new ItemStack(BuildCraftSilicon.redstoneChipset, 1, 1)
                                                                });
    	*/                                                              
    	//####################Gold Power Core
    	ModLoader.addName(new ItemStack(APSPowerCoreItem, 1, 2), "Gold Power Core");
    	AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {
                                                                new ItemStack(APSPowerCoreItem, 1, 1), 
                                                                new ItemStack(Item.ingotGold, 2)}, 
                                                                7500, 
                                                                new ItemStack(APSPowerCoreItem, 1, 2)
                                                                ));
    	/*ModLoader.addRecipe(new ItemStack(APSPowerCoreItem, 1, 2), new Object[]{ "IrI", "GRG", "IrI",
                                                                Character.valueOf('I'), Item.ingotIron,
                                                                Character.valueOf('G'), BuildCraftCore.goldGearItem,
                                                                Character.valueOf('r'), Item.redstone,
                                                                Character.valueOf('R'), new ItemStack(BuildCraftSilicon.redstoneChipset, 1, 2)
                                                                });
    	*/
    	                                                                
    	//####################Diamond Power Core
    	ModLoader.addName(new ItemStack(APSPowerCoreItem, 1, 3), "Diamond Power Core");
    	AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[] {
                                                                new ItemStack(APSPowerCoreItem, 1, 2), 
                                                                new ItemStack(Item.diamond, 2)}, 
                                                                10000, 
                                                                new ItemStack(APSPowerCoreItem, 1, 3)
                                                                ));
    	/*ModLoader.addRecipe(new ItemStack(APSPowerCoreItem, 1, 3), new Object[]{ "IrI", "GRG", "IrI",
                                                                Character.valueOf('I'), Item.ingotIron,
                                                                Character.valueOf('G'), BuildCraftCore.diamondGearItem,
                                                                Character.valueOf('r'), Item.redstone,
                                                                Character.valueOf('R'), new ItemStack(BuildCraftSilicon.redstoneChipset, 1, 3)
                                                                });
    	*/
    	//####################Control Panel
    	/*ModLoader.addRecipe(new ItemStack(APSControlPanelItem), new Object[]{ " r ", "PCG", " s ",
    															Character.valueOf('r'), Item.redstone,
													            Character.valueOf('P'), Block.thinGlass,
													            Character.valueOf('C'), new ItemStack(APSPowerCoreItem, 1, 1),
													            Character.valueOf('G'), BuildCraftCore.ironGearItem,
													            Character.valueOf('s'), Item.stick
													            });*/
    	
    	//################### liquid energy containers
		insulatedBottle = (new ItemInsulatedBottle(insulatedBottleID)).setItemName("insulatedbottle");
		ModLoader.addName(insulatedBottle, "Insulated Bottle");
		bottledEnergy = (new ItemBottledEnergy(bottledEnergyID)).setItemName("liquidenergycan");
		ModLoader.addName(bottledEnergy,"Liquid Energy Can");
    	
		//################### Energy crystal
		EnergyCrystal = (new ItemEnergyCrystal(energyCrystalID).setItemName("Energy Crystal"));
    	
    	//####################APS Meta Block
    	ModLoader.registerBlock(APSMetaBlockEnergy);
    	ModLoader.registerBlock(APSMetaBlockMachine);
    	Item.itemsList[APSMetaBlockEnergy.blockID] = APSMetaBlockEnergyItem;
    	Item.itemsList[APSMetaBlockMachine.blockID] = APSMetaBlockMachineItem;
	}
	
	@Override
	public void clientInit()
	{
		Localization.addLocalization("/lang/aps/", DefaultProps.DEFAULT_LANGUAGE);
	}
	
	public void postInit() {}
	
	public static void AddMetaSubblock(int Index, Class <? extends TileEntityAPS> Ent, String InternalName, String IngameName, APSBlockTypes type)
	{
		AddMetaSubblock(Index, Ent, InternalName, IngameName, type, null, false, false);
	}
	
	public static void AddMetaSubblock(int Index, Class <? extends TileEntityAPS> Ent, String InternalName, String IngameName, APSBlockTypes type, boolean ProviderTriggers, boolean ProviderActions)
	{
		AddMetaSubblock(Index, Ent, InternalName, IngameName, type, null, ProviderTriggers, ProviderActions);
	}
	
	public static void AddMetaSubblock(int Index, Class <? extends TileEntityAPS> Ent, String InternalName, String IngameName, APSBlockTypes type, APSKitItemAction action)
	{
		AddMetaSubblock(Index, Ent, InternalName, IngameName, type, action, false, false);
	}
	
	public static void AddMetaSubblock(int Index, Class <? extends TileEntityAPS> Ent, String InternalName, String IngameName, APSBlockTypes type, APSKitItemAction action, boolean ProvidesTriggers, boolean ProvidesActions)
	{
		ModLoader.registerTileEntity(Ent, InternalName);
		
		int offset = 0;
		if (type == APSBlockTypes.Machine)
			offset = 16;
			
			APSMetaSubs[Index + offset] = new APSMetaSub(Index, Ent, InternalName, IngameName, type);
		
		if (action != null)
			ItemAPSKit.registerKit(Index + offset, 32 + Index + offset, IngameName, action);
		else
			ItemAPSKit.registerKit(Index + offset, 32 + Index + offset, IngameName);
	}
}
